package com.health.manage.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.health.manage.pojo.dto.AssessDto;
import com.health.manage.pojo.entity.Assess;
import com.health.manage.service.IAssessService;
import com.health.manage.util.DateUtils;
import com.health.manage.util.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *
 * @Description: 健康评估管理控制器
 * @author: user
 */
@RestController
@RequestMapping("/assess")
@Api(tags = "健康评估管理")
@CrossOrigin
public class AssessController extends BaseController{

    @Autowired
    private IAssessService assessService;

    @PostMapping("list")
    @ApiOperation(value = "获取列表数据", notes = "", httpMethod = "POST")
    public ResponseResult<Page<Assess>> list(@RequestBody AssessDto assessDto){

        Page<Assess> dataList = this.assessService.getPageData(assessDto);
        return ResponseResult.success(dataList);
    }

    @PostMapping("score")
    @ApiOperation(value = "获取列表数据", notes = "", httpMethod = "POST")
    public ResponseResult<JSONObject> score(@RequestBody AssessDto assessDto){

        JSONObject jsonObject = this.assessService.getScoreData(assessDto);
        return ResponseResult.success(jsonObject);
    }

    @PostMapping("add")
    @ApiOperation(value = "添加数据", notes = "", httpMethod = "POST")
    public ResponseResult<Boolean> add(@RequestBody Assess assess){

        assess.setCreateDate(DateUtils.getDate());
        assess.setCreateId(this.currentUser().getId()+"");
        Boolean result = this.assessService.addData(assess);
        return ResponseResult.success(result);
    }

    @PostMapping("update")
    @ApiOperation(value = "更新数据", notes = "", httpMethod = "POST")
    public ResponseResult<Boolean> update(@RequestBody Assess assess){

        Boolean result = this.assessService.updateData(assess);
        return ResponseResult.success(result);
    }

    @DeleteMapping("{id}")
    @ApiOperation(value = "删除数据", notes = "", httpMethod = "DELETE")
    public ResponseResult<Boolean> delete(@PathVariable Long id){

        Boolean result = this.assessService.deleteData(id);
        return ResponseResult.success(result);
    }



}
